package com.totoro.mongo.service;

import com.mongodb.CommandResult;
import com.mongodb.MongoOptions;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.ScriptOperations;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by Niki on 2018/3/6 11:20
 */
@Service
public class DemoService {
    @Resource
    MongoTemplate mongoTemplate;

    /**
     * 获取当前连接的Mongo的版本
     *
     * @return
     */
    public String getMongoVersion() {
        String info = mongoTemplate.getDb().getMongo().toString();
        System.out.println(info);
        CommandResult result = mongoTemplate.getDb().command("version()");
        if(result.ok()){
            System.out.println(result.keySet().toString());
            System.out.println(result.values().toString());
        }


        ScriptOperations operations = mongoTemplate.scriptOps();
        System.out.println(operations.toString());


        System.out.println(mongoTemplate.getDb().getMongo().toString());

        CommandResult statsResult = mongoTemplate.getDb().getStats();
        if(statsResult.ok()){
            System.out.println(statsResult.keySet().toString());
            System.out.println(statsResult.values().toString());
        }

        MongoOptions mongoOptions = mongoTemplate.getDb().getMongo().getMongoOptions();
        System.out.println(mongoOptions.getDescription());
        System.out.println(mongoOptions.toString());
        mongoTemplate.getDb().getMongo();
        return null;
    }
}
